package com.doctor.config;


import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import com.doctor.common.Constat;
import com.doctor.lucene.SearcherKit;
import com.doctor.service.DoctorService;

@Component
public class SiteConfig implements InitializingBean{
	

	@Resource
	private ServletContext servletContext;
	
	@Resource
	private SearcherKit searcherKit;
	
	@Resource
	private DoctorService doctorService;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		servletContext.setAttribute("siteName", Constat.SITENAME);
		reloadIndex();
	}

	/**
	 * 重建所有文章索引
	 */
	private void reloadIndex() {
		searcherKit.reloadIndex(doctorService.findAllMan());
	}
}
